package com.example.awale;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;

public class ImageAdapter extends BaseAdapter {
	private Context mContext;
	public int[] mThumbIds;
	public int[] posi;
	
	public ImageAdapter(Context c)
	{
		mContext = c;
		mThumbIds=new int[24];
		init();
	}
	
	public void init()
	{
		for(int i=0;i<24;i++)
		{
			mThumbIds[i]=R.drawable.three;

		}
		mThumbIds[0]=R.drawable.zero;
		mThumbIds[7]=R.drawable.zero;
		mThumbIds[16]=R.drawable.zero;
		mThumbIds[23]=R.drawable.zero;
		for(int i=8;i<16;i++)
		{
			mThumbIds[i]=R.drawable.zero;
		}
	}

	public void changement_position(int i,int valeur)
	{		
		if(valeur==0)mThumbIds[i]=R.drawable.zero;
		if(valeur==1)mThumbIds[i]=R.drawable.one;
		if(valeur==2)mThumbIds[i]=R.drawable.two;
		if(valeur==3)mThumbIds[i]=R.drawable.three;
		if(valeur==4)mThumbIds[i]=R.drawable.four;
		if(valeur==5)mThumbIds[i]=R.drawable.five;
		if(valeur==6)mThumbIds[i]=R.drawable.six;
		if(valeur==7)mThumbIds[i]=R.drawable.seven;
		if(valeur==8)mThumbIds[i]=R.drawable.eight;
		if(valeur==9)mThumbIds[i]=R.drawable.nine;
		if(valeur==10)mThumbIds[i]=R.drawable.ten;
		if(valeur==11)mThumbIds[i]=R.drawable.eleven;
		if(valeur==12)mThumbIds[i]=R.drawable.twelve;
		if(valeur==13)mThumbIds[i]=R.drawable.thirteen;
		if(valeur==14)mThumbIds[i]=R.drawable.fourteen;
		if(valeur==15)mThumbIds[i]=R.drawable.fifteen;
		if(valeur==16)mThumbIds[i]=R.drawable.sixteen;
	}
	
	public void initPosition(int[] posi)
	{
		int j=0;
		for(int i=0;i<14;i++)
		{
			if(i==0)j=17;
			if(i==1)j=18;
			if(i==2)j=19;
			if(i==3)j=20;
			if(i==4)j=21;
			if(i==5)j=22;
			if(i==6)j=15;
			if(i==7)j=6;
			if(i==8)j=5;
			if(i==9)j=4;
			if(i==10)j=3;
			if(i==11)j=2;
			if(i==12)j=1;
			if(i==13)j=7;
			changement_position(j,posi[i]);
		}
	}
	@Override
	public int getCount() {
		return mThumbIds.length ;
	}

	@Override
	public Object getItem(int position) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ImageView imageView;
        if (convertView == null) {  // if it's not recycled, initialize some attributes
            imageView = new ImageView(mContext);
            imageView.setLayoutParams(new GridView.LayoutParams(80, 80));
            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
            imageView.setPadding(10, 10, 10, 10);
            
        } else {
            imageView = (ImageView) convertView;
        }

        imageView.setImageResource(mThumbIds[position]);
        return imageView;
	}
	
	

}
